package fun.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import org.lex.swing.ActionBuilder;


public class MainMenuBar extends JMenuBar {
	private JMenu fileMenu = null;
	private JMenuItem exitMenuItem = null;
	// ====================================
	protected FunMainFrame mainFrame = null;

	public MainMenuBar(FunMainFrame mainFrame) {
		super();
		this.mainFrame = mainFrame;
		this.initialize();
	}

	private void initialize() {
		this.add(this.getFileMenu());
		this.add(new org.lex.swing.plaf.widget.LookAndFeelMenu(mainFrame));
		// test
		this.add(Box.createHorizontalGlue());
		this.add(new JButton("X"));
	}

	private JMenu getFileMenu() {
		if (fileMenu == null) {
			fileMenu = new JMenu();
			fileMenu.setText("File");
			fileMenu.setMnemonic('F');
			fileMenu.add(getExitMenuItem());
		}
		return fileMenu;
	}

	private JMenuItem getExitMenuItem() {
		if (exitMenuItem == null) {
			exitMenuItem = new JMenuItem(new ActionBuilder("Exit").setActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					mainFrame.exit();
				}
			}).setAcceleratorKey(KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_MASK)));
		}
		return exitMenuItem;
	}
}
